home *** CD-ROM | disk | FTP | other *** search
- #include "DeskLib:WimpSWIs.h"
- #include "DeskLib:Kbd.h"
- #include "DeskLib:Wimp.h"
- #include "DeskLib:Window.h"
-
- #include "Shell.RectSave.h"
- #include "Shell.Save102.h"
- #include "Shell.FindWind.h"
-
-
-
-
-
- static BOOL Shell_RectSaver( char *filename, void *reference)
- /* This calls the rect's saver, passing the rects info pointer. */
- {
- Shell_rectblock *r = (Shell_rectblock *) reference;
-
- if ( !r->saver) {
- Error_Report( 0, Error_PLACE "Trying to save a rect-type which hasn't got a saver");
- return TRUE;
- }
- return (r->saver)( filename, r);
- }
-
-
-
-
-
-
- static int Shell_RectRAMTransferer(
- task_handle sourcetask,
- void *reference,
- task_handle desttask,
- void *destbuffer,
- unsigned int buffersize,
- int progress
- )
- /* This is just a veneer which casts 'reference' into a (Shell_rectblock *) and then */
- /* calls the rectangles ramsaver. */
- {
- Shell_rectblock *r = (Shell_rectblock *) reference;
-
- if ( !r->ramsaver) {
- Error_Report( 0, Error_PLACE "Trying to RAM-transfer a rect-type which hasn't got a RAM transferer");
- return -1;
- }
-
- return (r->ramsaver)( sourcetask, r, desttask, destbuffer, buffersize, progress);
- }
-
-
-
-
-
-
- static BOOL PointInRect(wimp_coord *point, wimp_rect *rectangle)
- /* corrected version of the one in DL */
- {
- if ( point->x < rectangle->min.x) return FALSE;
- if ( point->x > rectangle->max.x) return FALSE;
- if ( point->y < rectangle->min.y) return FALSE; /* was rectangle->min.x */
- /* changed JS Tue 08 Mar 1994 */
- if ( point->y > rectangle->max.y) return FALSE;
- return TRUE;
- }
-
-
-
-
-
-
-
- static Shell_rectblock *Shell_FindRectBlockFromPtr( mouse_block *ptrinfo)
- /* Finds the rectblock (if any) that is under the pointer */
- { Shell_windblock *w;
- Shell_rectblock *r;
- window_state state;
- wimp_point pos;
-
- w = Shell_FindWindBlock( ptrinfo->window);
- if (!w) return NULL; /* window is not a Shell window */
-
- pos = ptrinfo->pos;
- Wimp_GetWindowState( ptrinfo->window, &state);
- Coord_PointToWorkArea( &pos, (convert_block *) &state.openblock.screenrect);
-
- /* Search backwords so that most recent rects are looked for first. */
- for ( r = LinkList_LastItem( &w->anchor); r; r=LinkList_PreviousItem( &r->header)) {
- if ( PointInRect( &pos, &r->rect)) return r;
- }
-
- return NULL;
- }
-
-
-
-
-
- static BOOL Shell_RectSaveClickHandler( event_pollblock *event, void *reference)
- /* This fn is called whenever there is a click on any window */
- /* It opens a transient save-window if the click is Shift-Menu */
- /* 'ref' is the Save_saveblock which was inited by */
- /* Shell_InitRectSave. We need to fill in the details of the */
- /* actual rect that was clicked on. */
- {
- Shell_rectblock *r;
- mouse_block ptrinfo;
- Shell_Save102_saveblock *saveblock = (Shell_Save102_saveblock *) reference;
-
- if ( !Kbd_KeyDown( inkey_SHIFT)) return FALSE;
-
- Wimp_GetPointerInfo( &ptrinfo);
- r = Shell_FindRectBlockFromPtr( &ptrinfo);
-
- if ( !r) return FALSE; /* Click wasn't on a rect */
- if ( !r->saver) return FALSE; /* Click was on a rect, but the */
- /* rect hasn't got a save function. */
- /* Should really continue the search */
- /* in case there is a Shell rect which */
- /* is beneath this rect. */
-
-
- saveblock->ref = (void *) r;
- saveblock->estimatedsize = r->size;
- saveblock->ramsaver = (r->ramsaver) ? Shell_RectRAMTransferer : NULL;
- /* We use the generic Shell savers which call the rect's own saver. */
-
- Shell_Save102_SetFiletype( saveblock, r->filetype);
-
- Wimp_CreateMenu(
- (menu_block *) saveblock->window,
- event->data.mouse.pos.x,
- event->data.mouse.pos.y
- );
-
- return TRUE;
- }
-
-
-
-
-
-
- void Shell_InitRectSave(
- char *windowname,
- icon_handle dragsprite,
- icon_handle okbutton,
- icon_handle cancelbutton,
- icon_handle filenameicon
- ) {
-
- Shell_Save102_saveblock *saveblock;
-
- saveblock = Shell_Save102_InitSaveWindowHandler(
- Window_Create( windowname, 0),
- TRUE, /* is menu */
- FALSE, /* isn't a window */
- FALSE, /* don't release handlers after a save */
- dragsprite,
- okbutton,
- cancelbutton,
- filenameicon,
- Shell_RectSaver,
- NULL, /* ramsaver filled in later */
- NULL, /* result handler */
- 50, /* est. size */
- 0xfff, /* Default Filetype. */
- NULL /* info */
- );
-
- Event_Claim( event_CLICK, event_ANY, event_ANY, Shell_RectSaveClickHandler, (void *) saveblock);
- return;
- }
-
-